package com.myk.game.shapechesstool.data;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import com.myk.game.shapechesstool.R;

import java.util.HashMap;

//游戏的声音资源
public class SoundData {

    private static final SoundPool mSoundPlayer = new SoundPool.Builder().setMaxStreams(5).build();
    private static final HashMap<Integer, Integer> soundMaps = new HashMap<>();

    /**
     * 加载声音资源
     */
    public static void load(Context context) {
        soundMaps.put(Type.FALL, mSoundPlayer.load(context, R.raw.fall, 1));
        soundMaps.put(Type.PICK, mSoundPlayer.load(context, R.raw.pick, 1));
        soundMaps.put(Type.ERROR, mSoundPlayer.load(context, R.raw.error, 1));
    }

    /**
     * 根据类型播放声音
     */
    public static void play(int soundType) {
        int soundId = soundMaps.get(soundType);
        mSoundPlayer.play(soundId, 1, 1, 0, 0, 1);
    }

    /**
     * 播放声音并控制频率和速率
     */
    public static void play(int soundType, int loop, float rate) {
        int soundId = soundMaps.get(soundType);
        mSoundPlayer.play(soundId, 1, 1, 0, loop, rate);
    }

    public interface Type {
        /**
         * 落子声
         */
        int FALL = 0;
        /**
         * 提子声
         */
        int PICK = 1;
        /**
         * 错误音
         */
        int ERROR = 2;
    }

}
